
def sale_num(key):
    total = 0
    num = []
    while True:
        item=yield
        if not item:
            break
        total += item
        num.append(item)

    return total, num

def middle(key,reslut):
    while True:
        total,num=yield  from  sale_num(key)
        reslut[key]=(total,num)
        print("{}销量统计完成".format(key))


def main():
    data_set={
        "手机":[100,200,300],
        "电脑":[3,4,5,7],
        "平板":[3,4,5,7,8]
    }

    result={}
    for key,data in data_set.items():
        g=middle(key,result)
        g.send(None)
        for i in data:
            g.send(i)
        g.send(None)
        g.close()

    print(result)
if __name__ == '__main__':
    main()